
package org.come.until;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.ImageObserver;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicScrollBarUI;

import com.updateNew.MyIsif;

public class ScrollUI extends BasicScrollBarUI {
	private final Color frameColor = new Color(23, 11, 15);

	private String gdt;
	private String upurl;
	private String dwurl;
	public ScrollUI() {
		//单按钮
		if("水墨UI".equals(MyIsif.getStyle())) {
			gdt = "skin/8100226/button/23.png";
			upurl = "skin/8100226/button/69.png";
			dwurl = "skin/8100226/button/68.png";
		}else {
			gdt = "inkImg/hongmu/2/gundongtiao_副本_副本.png";
			upurl = "inkImg/hongmu/2/35_png.button.xy_vscroll$down_副本.png";
			dwurl = "inkImg/hongmu/2/42_png.button.btn_1_副本.png";
		}
	}
	@Override
    public Dimension getPreferredSize(JComponent c) {
		return new Dimension(16, 16);
	}

	@Override
    public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
		super.paintThumb(g, c, thumbBounds);
		int tw = thumbBounds.width;
		int th = thumbBounds.height;
		g.translate(thumbBounds.x, thumbBounds.y);
		Graphics2D g2 = (Graphics2D)g;
		GradientPaint gp = null;
		if("水墨UI".equals(MyIsif.getStyle())) {
			gp = new GradientPaint(0.0F, 0.0F, new Color(50,126,115), (float)tw, 0.0F, new Color(50,126,115));
		}else {
			if (this.scrollbar.getOrientation() == 1) {
				gp = new GradientPaint(0.0F, 0.0F, new Color(87, 4, 8), (float)tw, 0.0F, new Color(87, 4, 8));
			}
		}

		g2.setPaint(gp);
		g2.fillRoundRect(0, 0, tw, th, 5, 5);
		if("水墨UI".equals(MyIsif.getStyle())) {
			g2.setColor(new Color(50,126,115));
		}else {
			g2.setColor(new Color(159, 73, 36));
		}
		g2.drawRoundRect(0, 0, tw, th, 5, 5);
	}

	@Override
    public void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
		Graphics2D g2 = (Graphics2D)g;
		GradientPaint gp = null;
		if (this.scrollbar.getOrientation() == 1) {
			gp = new GradientPaint(0.0F, 0.0F, new Color(23, 11, 15), (float)trackBounds.width, 0.0F, new Color(23, 11, 15));
		}

		if (this.scrollbar.getOrientation() == 0) {
			gp = new GradientPaint(0.0F, 0.0F, new Color(198, 178, 151), 0.0F, (float)trackBounds.height, new Color(234, 214, 190));
		}

		g2.setPaint(gp);
		g2.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);
		if("水墨UI".equals(MyIsif.getStyle())) {
			g2.setColor(new Color(64,111,91));
		}else {
			g2.setColor(new Color(31, 7, 8));
		}
		g2.drawRect(trackBounds.x, trackBounds.y, trackBounds.width - 1, trackBounds.height - 1);
		if (this.trackHighlight == 1) {
			this.paintDecreaseHighlight(g);
		}

		if (this.trackHighlight == 2) {
			this.paintIncreaseHighlight(g);
		}

	}

	@Override
    protected JButton createIncreaseButton(int orientation) {
		return new BasicArrowButton(orientation) {
			@Override
            public void paintTriangle(Graphics g, int x, int y, int size, int direction, boolean isEnabled) {
				Graphics2D g2 = (Graphics2D)g;
				GradientPaint gp = null;
				Image arrowImg = null;
				String gdt = "";

				switch(this.getDirection()) {
					case 5:
						arrowImg = (new ImageIcon(upurl)).getImage();
					default:
						g2.drawImage(arrowImg, 0, 0, 20, 20, null);
				}
			}
		};
	}

	@Override
    protected JButton createDecreaseButton(int orientation) {
		return new BasicArrowButton(orientation) {
			@Override
            public void paintTriangle(Graphics g, int x, int y, int size, int direction, boolean isEnabled) {
				Graphics2D g2 = (Graphics2D)g;
				GradientPaint gp = null;
				Image arrowImg = null;
				switch(this.getDirection()) {
					case 1:
						arrowImg = (new ImageIcon(dwurl)).getImage();
					default:
						g2.drawImage(arrowImg, 0, 0, 20, 20, null);
				}
			}
		};
	}
}
